﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Nhom14_HTTTHD_BuyMe
{
    public partial class sell_website : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["login"] != "1")
                Response.Redirect("login.aspx?url=sell-website.aspx");
        }

        protected void Info_Submit_Click(object sender, EventArgs e)
        {
            using (websitebrokenEntities context = new websitebrokenEntities())
            {
                //try
                {
                    if (FileUploadControl.PostedFile.ContentType == "image/jpeg")
                    {
                        if (FileUploadControl.PostedFile.ContentLength < 502400)
                        {
                           // public int SellWebsite(int id_account, int SiteStatus, string SiteName, string SiteURL, string Description, string Visitor, string PageView, string Income, string Cost, string Disk, String Bandwidth, string member, string price, CheckBoxList CheckBoxList1, int id_category)
                            
                            /*-----------------------------------*/
                            int par1 = Convert.ToInt32(Session["user"]);
                            int par8 = Convert.ToInt32(Info_Sitestatus.Text);

                            string par9 = Info_Sitename.Text;
                            string par2 = Info_SiteURL.Text;
                            string par3 = Info_Description.InnerText;
                            string par10 = Info_Visitor.Text;
                            string par4 = Info_Pageview.Text;
                            string par11 = Info_Income.Text;
                            string par12 = Info_Cost.Text;
                            string par13 = Info_Disk.Text;
                            string par14 = Info_Bandwidth.Text;
                            string par15 = Info_Member.Text;
                            string par5 = Info_Price.Text;
                            int par6 = Convert.ToInt32(Info_Category.SelectedValue);
                            
//public int Sell(int id_account(1), string SiteURL(2), string Description(3), string price(4), int id_category(5), string PageView(6), int type(7), 
//int SiteStatus(8), string SiteName(9), string Visitor(10), string Income(11), string Cost(12), string Disk(13), String Bandwidth(14), string member(15))
                            string address = "http://localhost:49744/WebService1.asmx";
                            string function = "Sell";
                         
                            int res = (int)WebserviceInvoker.WSInvoker.CallWebService(address, "WebService1", function, new object[] { par1, par2, par3, par4, par5, par6, 2, par8, par9, par10, par11, par12, par13, par14, par15 });

                            if (res != 0)
                            {
                                website obj = new website();
                                var kq = from s in context.websites
                                         where s.id == res
                                         select s;
                                obj = kq.First();
                                
                                foreach (ListItem li in CheckBoxList1.Items)
                                {
                                    if (li.Selected == true)
                                    {
                                        int value_id = Convert.ToInt32(li.Value);
                                        var result = from x in context.site_business
                                                     where x.id == value_id
                                                     select x;                                           

                                        site_business web = result.First();
                                        obj.site_business.Add(web);
                                    }
                                }
                                context.SaveChanges();
                                
                                string filename = res + ".jpg";
                                FileUploadControl.SaveAs(Server.MapPath("~/Images/") + filename);

                                string url_re = "special-listing.aspx?url=" + Info_SiteURL.Text + "&id=" + res + "&type=1";
                                Response.Redirect(url_re);
                            }
                            
                            
                        }
                        else
                            StatusLabel.Text = "Upload status: The file has to be less than 500 kb!";
                    }
                    else
                        StatusLabel.Text = "Upload status: Only JPEG files are accepted!";
                }
                    /*
                catch (Exception ex)
                {
                    StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }*/
                
                
                
                
            }
        }
    }
}